package testcase;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import entity.Dice;

public class DiceTest {
	private Dice dice;

	@Before
	public void setUp() throws Exception {
		dice = new Dice("/images/dice/Dices.png",47,57);
	}

	@After
	public void tearDown() throws Exception {}
	
	/**Make sure the return value of "getValue function within 1-6*/
	@Test
	public void testGetValue() {
		 class DiceStub extends Dice{
			 public DiceStub(String img,int cropwidth, int cropheight) {
				 super(img,cropwidth,cropheight);
			 }
             
            public int indexStub = 0;
            public void setIndexStub(int x) {indexStub = x;}
            @Override
            public int getCurrentImgIndex()
             {
            	 return indexStub; 
             }
		 }
		 DiceStub diceStub = new DiceStub("/images/dice/Dices.png",47,57);
		 diceStub.setIndexStub(-1);
		 int result = diceStub.getValue();
		 assertEquals(1, result);
		 
		 diceStub.setIndexStub(0);
		 result = diceStub.getValue();
		 assertEquals(6, result);
		 
		 diceStub.setIndexStub(1);
		 result = diceStub.getValue();
		 assertEquals(5, result);
		 
		 diceStub.setIndexStub(2);
		 result = diceStub.getValue();
		 assertEquals(4, result);
		 
		 diceStub.setIndexStub(3);
		 result = diceStub.getValue();
		 assertEquals(3, result);
		 
		 diceStub.setIndexStub(4);
		 result = diceStub.getValue();
		 assertEquals(2, result);
		 
		 diceStub.setIndexStub(5);
		 result = diceStub.getValue();
		 assertEquals(1, result);
		 
		 diceStub.setIndexStub(6);
		 result = diceStub.getValue();
		 assertEquals(6, result);
		 
	}
	
	/**Make sure the the initial of Dice is correct to crop and show the correct image with correct value*/
	@Test
	public void testIntegration(){
		/**initial*/
		assertEquals(-1,dice.getCurrentImgIndex());
		assertEquals(6, dice.getImgsListSize());
		assertEquals(1,dice.getValue());
		
		/**when imgIndex = 0*/
		dice.setNextImage();
		assertEquals(6,dice.getValue());
		
		/**when imgIndex = 1*/
		dice.setNextImage();
		assertEquals(5,dice.getValue());
		
		/**when imgIndex = 2*/
		dice.setNextImage();
		assertEquals(4,dice.getValue());
		
		/**when imgIndex = 3*/
		dice.setNextImage();
		assertEquals(3,dice.getValue());
		
		/**when imgIndex = 4*/
		dice.setNextImage();
		assertEquals(2,dice.getValue());
		
		/**when imgIndex = 5*/
		dice.setNextImage();
		assertEquals(1,dice.getValue());
		
		/**when imgIndex = 0*/
		dice.setNextImage();
		assertEquals(0,dice.getCurrentImgIndex());
		assertEquals(6,dice.getValue());
		
		/**when imgIndex = 1*/
		dice.setNextImage();
		assertEquals(5,dice.getValue());
	}
}
